package com.hc.util;

import com.hc.model.QcMonitorModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;

import java.util.Date;
import java.util.List;

/**
 * @author LiuZhiHao
 * @date 2019/9/26 19:43
 * 描述:
 **/
public class QcEqMonExcelUtil {


    public static void exportExcel(HSSFWorkbook workbook, String s, List<QcMonitorModel> qcMonitorModels) {
        HSSFCellStyle cellStyle = ExcelUtils.createErrorStyle(workbook, (short) 10, false, true, (short) 0);
        switch (s) {
            case "1":
                HSSFSheet sheet = workbook.createSheet("倒置显微镜");
                //设置头
                String[] headers = {"设备名称", "检测类型", "是否校准", "下次校准时间", "备注","操作者", "操作时间"};
                HSSFRow row = sheet.createRow(0);
                ExcelUtils.createCell(headers, row, workbook,sheet);
                int rowNum = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet.createRow(rowNum);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    String stmMonitorType = m.getStmMonitorType();
                    if (StringUtils.equals(stmMonitorType,"1")){
                        rown.createCell(1).setCellValue("恒温版");
                    }else {
                        rown.createCell(1).setCellValue("激光");
                    }
                    String isCalibration = m.getIsCalibration();
                    if (StringUtils.equals(isCalibration, "1")) {
                        rown.createCell(2).setCellValue("已校准");
                    } else {
                        HSSFCell hssfCell = rown.createCell(2);
                        hssfCell.setCellValue("未校准");
                        hssfCell.setCellStyle(cellStyle);
                    }
                    Date nextCalibrationTime = m.getNextCalibrationTime();
                    rown.createCell(3).setCellValue(QcEqRdExcelUtil.formatDate(nextCalibrationTime));
                    String remark = m.getRemark();
                    if (StringUtils.isNotEmpty(remark)) {
                        rown.createCell(4).setCellValue(remark);
                    }
                    rown.createCell(5).setCellValue(m.getCreateName());
                    rown.createCell(6).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum++;
                }
                break;
            case "2":
                HSSFSheet sheet1 = workbook.createSheet("工作台");
                //设置头
                String[] headers1 = {"设备名称",  "是否校准", "下次校准时间", "备注","操作者", "操作时间"};
                HSSFRow row1 = sheet1.createRow(0);
                ExcelUtils.createCell(headers1, row1, workbook,sheet1);
                int rowNum1 = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet1.createRow(rowNum1);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    String isCalibration = m.getIsCalibration();
                    if (StringUtils.equals(isCalibration, "1")) {
                        rown.createCell(1).setCellValue("已校准");
                    } else {
                        HSSFCell hssfCell = rown.createCell(1);
                        hssfCell.setCellValue("未校准");
                        hssfCell.setCellStyle(cellStyle);
                    }
                    Date nextCalibrationTime = m.getNextCalibrationTime();
                    rown.createCell(2).setCellValue(QcEqRdExcelUtil.formatDate(nextCalibrationTime));
                    String remark = m.getRemark();
                    if (StringUtils.isNotEmpty(remark)) {
                        rown.createCell(3).setCellValue(remark);
                    }
                    rown.createCell(4).setCellValue(m.getCreateName());
                    rown.createCell(5).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum1++;
                }
                break;
            case "3":
                HSSFSheet sheet2 = workbook.createSheet("常用仪器维护");
                //设置头
                String[] headers2 = {"设备名称",  "保养时间", "维护项目", "备注","操作者", "操作时间"};
                HSSFRow row2 = sheet2.createRow(0);
                ExcelUtils.createCell(headers2, row2, workbook,sheet2);
                int rowNum2 = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet2.createRow(rowNum2);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    Date maintainTime = m.getMaintainTime();
                    rown.createCell(1).setCellValue(QcEqRdExcelUtil.formatDate(maintainTime));
                    String maintenanceProjects = m.getMaintenanceProjects();
                    if (StringUtils.equals(maintenanceProjects,"1")){
                        rown.createCell(2).setCellValue("清洁");
                    }else if (StringUtils.equals(maintenanceProjects,"2")){
                        rown.createCell(2).setCellValue("定期保养");
                    }else if (StringUtils.equals(maintenanceProjects,"3")){
                        rown.createCell(2).setCellValue("更换耗材");
                    }else if (StringUtils.equals(maintenanceProjects,"5")){
                        rown.createCell(2).setCellValue("加水");
                    }
                    else {
                        rown.createCell(2).setCellValue("故障维护");
                    }
                    String remark = m.getRemark();
                    if (StringUtils.isNotEmpty(remark)) {
                        rown.createCell(3).setCellValue(remark);
                    }
                    rown.createCell(4).setCellValue(m.getCreateName());
                    rown.createCell(5).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum2++;
                }
                break;
            case "4":
                HSSFSheet sheet3 = workbook.createSheet("气瓶室");
                //设置头
                String[] headers3 = {"设备名称",  "更换时间", "更换气体", "更换后库存气体","操作者", "操作时间"};
                HSSFRow row3 = sheet3.createRow(0);
                ExcelUtils.createCell(headers3, row3, workbook,sheet3);
                int rowNum3 = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet3.createRow(rowNum3);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    rown.createCell(1).setCellValue(QcEqRdExcelUtil.formatDate(m.getReplacementTime()));
                    String replacementGas = m.getReplacementGas();
                    if (StringUtils.equals(replacementGas,"1")){
                        rown.createCell(2).setCellValue("CO2");
                    }else if (StringUtils.equals(replacementGas,"2")){
                        rown.createCell(2).setCellValue("N2");
                    }else {
                        rown.createCell(2).setCellValue("混合气");
                    }
                    String replacementGasCount = m.getReplacementGasCount();
                    rown.createCell(3).setCellValue(QcEqRdExcelUtil.gasChoose(replacementGasCount));
                    rown.createCell(4).setCellValue(m.getCreateName());
                    rown.createCell(5).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum3++;
                }
                break;
            case "5":
                HSSFSheet sheet4 = workbook.createSheet("CODA");
                //设置头
                String[] headers4 = {"设备名称", "已更换CODA","操作者", "操作时间"};
                HSSFRow row4 = sheet4.createRow(0);
                ExcelUtils.createCell(headers4, row4, workbook,sheet4);
                int rowNum4 = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet4.createRow(rowNum4);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    rown.createCell(1).setCellValue("是");
                    rown.createCell(2).setCellValue(m.getCreateName());
                    rown.createCell(3).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum4++;
                }
                break;
            case "6":
                HSSFSheet sheet5 = workbook.createSheet("回风清洗");
                //设置头
                String[] headers5 = {"设备名称", "已更换回风滤网","操作者", "操作时间"};
                HSSFRow row5 = sheet5.createRow(0);
                ExcelUtils.createCell(headers5, row5, workbook,sheet5);
                int rowNum5 = 1;
                for (QcMonitorModel m : qcMonitorModels) {
                    HSSFRow rown = sheet5.createRow(rowNum5);
                    rown.createCell(0).setCellValue(m.getDeviceName());
                    rown.createCell(1).setCellValue("是");
                    rown.createCell(2).setCellValue(m.getCreateName());
                    rown.createCell(3).setCellValue(QcEqRdExcelUtil.formatDate(m.getCreateTime()));
                    rowNum5++;
                }
                break;
            default:
                break;
        }


    }


}
